import { RouteIProps } from './types';
import { ReactNode, Suspense } from 'react';
import { Navigate } from 'react-router-dom';

import Login from '../views/user/Login';
import Index from '../views/Index';
import NotFound from '../views/notFound';

// 解决出现白屏问题
const lazyLoad = (children: ReactNode): ReactNode => {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <div>{children}</div>
    </Suspense>
  );
};

const routes: RouteIProps[] = [
  // {
  //   path: '/',
  //   element: <Navigate to="/login"></Navigate>,
  // },
  {
    path: '/user/login',
    label: '登录',
    element: <Login />,
  },
  {
    path: '/',
    label: '首页',
    element: <Index />,
    // children: [
    //   {
    //     path: 'dashboard',
    //     element: <Index />,
    //   },
    // ],
  },

  {
    path: '/notFound',
    label: '404',
    element: lazyLoad(<NotFound />),
  },
  {
    path: '*',
    label: '',
    element: <Navigate to="/notFound" />,
  },
];

export default routes;
